package org.grottarossa.ui.core.container;

import org.grottarossa.template.data.pojo.list.List;
import org.grottarossa.template.data.enums.EnumDataType;

import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;


public class ListContainer extends IndexedContainer
{
	/**
	 *
	 */
	private static final long serialVersionUID = -1594990664330686633L;

	private List myList;
	boolean bListEmpty = false;

	public ListContainer(List list)
	{
		//create my table
		this.myList = list;

		addContainerProperty(this.myList.getName(),EnumDataType.getJavaType(this.myList.getType()),null);
		if ( this.myList.isEmpty() ) {
			bListEmpty = true;
		}
		else {
			populateRecords();
		}
	}

	private void populateRecords()
	{
		java.util.ArrayList<Object> items = myList.getItems();

		for(int i=0;i<items.size();i++)//for each record
		{
			Object obj = addItem();
			Item it = getItem(obj);
			it.getItemProperty(this.myList.getName()).setValue(items.get(i));
		}
	}

	public List getMyList() {
		return myList;
	}

	public void setMyList(List mylist) {
		this.myList = mylist;
	}
}
